package com.yzy.fly.util.asm;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.util.ASMifier;
import org.objectweb.asm.util.Printer;
import org.objectweb.asm.util.Textifier;
import org.objectweb.asm.util.TraceClassVisitor;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * 这里的代码是参考自{@link org.objectweb.asm.util.Printer#main}
 */
public class ASMPrint {
    public static void main(String[] args) throws IOException {
        // (1) 设置参数
//        String className = "sample.HelloWorld";
//        String className = "com.yzy.fly.entity.core.Test";
        String className = "com.yzy.fly.entity.core.FlyClass";
//        String className = "com.yzy.fly.mapper.TestMapper";
        className = "com.yzy.fly.mapper.AsmFileLogMapper";
//        String className = "com.yzy.fly.type.FileType";
//        String className = "com.yzy.fly.type.RwstType";
//        String className = "com.yzy.fly.type.RwstType$FileType";
//        String className = "com.yzy.fly.type.ViewWidgetType";
//          String className = "com.yzy.fly.entity.role.FlyModel";
//          String className = "com.yzy.fly.util.asm.FlyModelTest";
//        String className = "com.yzy.fly.builder.com.yzy.fly.funtion.job.TestJobService";
//        int parsingOptions = ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG;
//        String className = FlyActressController.class.getName();
        int parsingOptions =  ClassReader.EXPAND_FRAMES | ClassReader.SKIP_DEBUG;
        boolean asmCode = true;

//        PrintASMCodeCore
//        PrintASMCodeTree
        // (2) 打印结果
        Printer printer = asmCode ? new ASMifier() : new Textifier();
        PrintWriter printWriter = new PrintWriter(System.out, true);
        TraceClassVisitor traceClassVisitor = new TraceClassVisitor(null, printer, printWriter);
        new ClassReader(className).accept(traceClassVisitor, parsingOptions);
    }
}
